/**
 * @description 马赛克处理
 * @link 原项目地址 : https://github.com/ifengzp/cocos-awesome
 */

import EventComponent from "../../../../quick/components/EventComponent";


const {ccclass, property} = cc._decorator;

@ccclass
export default class MasaicHandler extends EventComponent {


    /**@description 材质 */
    private material : cc.Material = null;

    onLoad(): void {
        super.onLoad && super.onLoad();

        this.material = cc.find("sprite",this.node).getComponent(cc.Sprite).getMaterial(0);

        //是否启用马赛克
        this.onN(cc.find("use",this.node),"toggle",this.onUseMasaic);
        //水平方向马赛克数量
        this.onN(cc.find("vCount",this.node),"slide",this.onChangeVCount);
        //垂直方向马赛克数量
        this.onN(cc.find("hCount",this.node),"slide",this.onChangeHCount);
    }

    private onUseMasaic( target : cc.Toggle ){
        this.material.define("USE_MASAIC",target.isChecked,0,true);
    }

    private onChangeVCount( target : cc.Slider ){
        this.material.setProperty("y_count",Math.floor(target.progress * 100))
    }

    private onChangeHCount( target : cc.Slider ){
        this.material.setProperty("x_count",Math.floor(target.progress * 100))
    }
}
